package com.app.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.app.common.EducationTool;
import com.app.common.ExperienceTool;
import com.app.common.IndustryTool;
import com.app.common.ScaleTool;
import com.app.mapper.JobFairCompanyMapper;
import com.app.mapper.JobFollowMapper;
import com.app.model.*;
import com.app.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description:收藏关注
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class JobFollowServiceImpl implements JobFollowService {
    @Autowired
    JobFollowMapper jobFollowMapper;
    @Autowired
    CustomerService customerService;
    @Autowired
    ComRecruitersService comRecruitersService;

    @Override
    public int selectAllCount(JobFollowModel model) {
        int count = 0;
        if(model!=null)
        {
            QueryWrapper<JobFollowModel> queryWrapper = new QueryWrapper<>();
            if(model.getCid()>0)
            {
                queryWrapper.select().eq("cid", model.getCid());
            }
            if(model.getFollow()>0)
            {
                queryWrapper.select().eq("follow", model.getFollow());
            }
            if(model.getFollowType()>0)
            {
                queryWrapper.select().eq("cid", model.getFollowType());
            }
            if(model.getRid()>0)
            {
                queryWrapper.select().eq("rid", model.getRid());
            }

            count = jobFollowMapper.selectCount(queryWrapper);
        }

        return count;
    }

    @Override
    public int insert(JobFollowModel model) {
        return jobFollowMapper.insert(model);
    }

    @Override
    public Object getFollowList(int type,UserModel user) {

        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if(type == 1)
        {
            CustomerModel cus = customerService.getCustomerById(user.getCId());
            //统计个人关注
            JobFollowModel JobFollow = new JobFollowModel();
            JobFollow.setCid(cus.getId());
            JobFollow.setFollow(1);
            JobFollow.setFollowType(1);
            int followCount = selectAllCount(JobFollow);
            json.put("followCount",followCount);
            //统计个人收藏
            JobFollowModel JobFollow2 = new JobFollowModel();
            JobFollow2.setCid(cus.getId());
            JobFollow2.setFollow(2);
            JobFollow2.setFollowType(1);
            int favouriteCount = selectAllCount(JobFollow2);
            json.put("favouriteCount",favouriteCount);
            //统计个人投递
            JobFollowModel JobFollow3 = new JobFollowModel();
            JobFollow3.setCid(cus.getId());
            JobFollow3.setFollow(5);
            JobFollow3.setFollowType(1);
            int deliveryCount = selectAllCount(JobFollow3);
            json.put("deliveryCount",deliveryCount);

            //统计个人谁看过我
            JobFollowModel JobFollow4 = new JobFollowModel();
            JobFollow4.setCid(cus.getId());
            JobFollow4.setFollow(4);
            JobFollow4.setFollowType(1);
            int lookMeCount = selectAllCount(JobFollow4);
            json.put("lookMeCount",lookMeCount);
        } else{
            ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());
            //统计HR关注
            JobFollowModel JobFollow = new JobFollowModel();
            JobFollow.setCid(com.getId());
            JobFollow.setFollow(1);
            JobFollow.setFollowType(2);
            int followCount = selectAllCount(JobFollow);
            json.put("followCount",followCount);
            //统计HR发布岗位数量
            int postCount = selectAllCount(JobFollow);
            json.put("postCount",postCount);
            //统计沟通
            JobFollowModel JobFollow3 = new JobFollowModel();
            JobFollow3.setCid(com.getId());
            JobFollow3.setFollow(3);
            JobFollow3.setFollowType(2);
            int speakCount = selectAllCount(JobFollow3);
            json.put("speakCount",speakCount);
            //统计谁看过我
            JobFollowModel JobFollow4 = new JobFollowModel();
            JobFollow4.setCid(com.getId());
            JobFollow4.setFollow(4);
            JobFollow4.setFollowType(2);
            int lookMeCount = selectAllCount(JobFollow4);
            json.put("lookMeCount",lookMeCount);
        }
        return json;
    }
}
